﻿using Wayloop.Blog.Core.Data.Entities;


namespace Wayloop.Blog.DataAccess.Mappings
{
    public class PostMap : AbstractEntityMap<Post>
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="PostMap"/> class.
        /// </summary>
        public PostMap()
        {
            Cache.AsNonStrictReadWrite();

            Map(m => m.Slug);
            Map(m => m.Title);
            Map(m => m.Summary);
            Map(m => m.Body);
            Map(m => m.CreatedOn);
            Map(m => m.ModifiedOn);
            Map(m => m.PublishedOn);

            HasMany(m => m.Comments)
                .KeyColumnNames.Add("PostId")
                .Cascade.AllDeleteOrphan()
                .Where("Status = 1")
                .Inverse()
                .Cache.AsReadWrite();
        }
    }
}